package com.joolun.web.controller.scrm;

import java.util.List;
import jakarta.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.joolun.common.annotation.Log;
import com.joolun.common.core.controller.BaseController;
import com.joolun.common.core.domain.AjaxResult;
import com.joolun.common.enums.BusinessType;
import com.joolun.system.domain.ScrmLiveCode;
import com.joolun.system.service.IScrmLiveCodeService;
import com.joolun.common.utils.poi.ExcelUtil;
import com.joolun.common.core.page.TableDataInfo;

/**
 * 企业活码Controller
 * 
 * @author joolun
 * @date 2025-02-25
 */
@RestController
@RequestMapping("/scrm/code")
public class ScrmLiveCodeController extends BaseController
{
    @Autowired
    private IScrmLiveCodeService scrmLiveCodeService;

    /**
     * 查询企业活码列表
     */
    @GetMapping("/list")
    public TableDataInfo list(ScrmLiveCode scrmLiveCode)
    {
        startPage();
        List<ScrmLiveCode> list = scrmLiveCodeService.selectScrmLiveCodeList(scrmLiveCode);
        return getDataTable(list);
    }

    /**
     * 导出企业活码列表
     */
    @PreAuthorize("@ss.hasPermi('system:code:export')")
    @Log(title = "企业活码", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, ScrmLiveCode scrmLiveCode)
    {
        List<ScrmLiveCode> list = scrmLiveCodeService.selectScrmLiveCodeList(scrmLiveCode);
        ExcelUtil<ScrmLiveCode> util = new ExcelUtil<ScrmLiveCode>(ScrmLiveCode.class);
        util.exportExcel(response, list, "企业活码数据");
    }

    /**
     * 获取企业活码详细信息
     */
    @PreAuthorize("@ss.hasPermi('system:code:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(scrmLiveCodeService.selectScrmLiveCodeById(id));
    }

    /**
     * 新增企业活码
     */
    @PreAuthorize("@ss.hasPermi('system:code:add')")
    @Log(title = "企业活码", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody ScrmLiveCode scrmLiveCode)
    {
        scrmLiveCode.setCreateBy(getUsername());
        return toAjax(scrmLiveCodeService.insertScrmLiveCode(scrmLiveCode));
    }

    /**
     * 修改企业活码
     */
    @PreAuthorize("@ss.hasPermi('system:code:edit')")
    @Log(title = "企业活码", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody ScrmLiveCode scrmLiveCode)
    {
        scrmLiveCode.setCreateBy(getUsername());
        return toAjax(scrmLiveCodeService.updateScrmLiveCode(scrmLiveCode));
    }

    /**
     * 删除企业活码
     */
    @PreAuthorize("@ss.hasPermi('system:code:remove')")
    @Log(title = "企业活码", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(scrmLiveCodeService.deleteScrmLiveCodeByIds(ids));
    }
}
